#include <signal.h>
#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <sys/types.h>
#include <cstdlib>
#include <cstring>
int SIGINT_N = 0;
int SIG40_N = 0;

void handler(int signo)
{
    if(signo == SIGINT)
        SIGINT_N++;
    else
        SIG40_N++;

}

int main()
{
    // signal(SIGINT,handler);
    // signal(40,handler);
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = handler;
    sigaction(SIGINT, &sa, NULL);
    sigaction(40, &sa, NULL);
    sigset_t block_set;
    sigset_t old_block_set;
    sigemptyset(&block_set);
    sigemptyset(&old_block_set);
    printf("屏蔽了2号信号和40号信号\n");
    sigaddset(&block_set, SIGINT);
    sigaddset(&block_set, 40);
    sigprocmask(SIG_SETMASK, &block_set, &old_block_set);
    for (int i = 0; i < 5; i++)
    {
        kill(getpid(), SIGINT);
        kill(getpid(), 40);
    }
    printf("解除对2好信号和40号信号的屏蔽\n");
    sigprocmask(SIG_SETMASK, &old_block_set, NULL);
    sleep(1);
    printf("SIGINT 处理次数:%d\n", SIGINT_N);
    printf("SIGRTMIN+6(40) 处理次数:%d\n", SIG40_N);
  
    return 0;
}